"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
//在类装饰器中target是该类的构造函数
function flyable(target) {
    target.prototype.swings = 2;
    target.prototype.fly = function () {
        console.log('会飞的方法fly');
    };
}
//普通装饰器
var Animal = /** @class */ (function () {
    function Animal() {
    }
    Animal = __decorate([
        flyable
    ], Animal);
    return Animal;
}());
;
var animal = new Animal();
animal.fly();
console.log(animal.swings);
//在类装饰器中target是该类的构造函数
function flyable2(swings) {
    return function (target) {
        target.prototype.swings = swings;
        target.prototype.fly = function () {
            console.log('会飞的方法fly222');
        };
    };
}
//装饰器工厂
var Animal2 = /** @class */ (function () {
    function Animal2() {
    }
    Animal2 = __decorate([
        flyable2(5)
    ], Animal2);
    return Animal2;
}());
;
var animal2 = new Animal2();
animal2.fly();
console.log(animal2.swings);
//2.3 属性装饰器、方法装饰器
//属性装饰器
//实例属性时，target是类的原型对象，key是属性名字
function instancePropertyDecorator(target, key) {
    target.protoName = '我是原型上的属性';
    console.log('instancePropertyDecorator=>', target, key);
}
//静态属性时，target是类的构造函数，key是属性名字
function classPropertyDecorator(target, key) {
    console.log('classPropertyDecorator=>', target, key);
}
//方法装饰器
//实例属性时，target是类的原型对象，key是属性名字，descriptor是属性描述符
function instanceMethodDecorator(target, key, descriptor) {
    console.log('instanceMethodDecorator=>', target, key, descriptor);
}
//静态属性时，target是类的原型对象，key是属性名字，descriptor是属性描述符
function classMethodDecorator(target, key, descriptor) {
    console.log('classMethodDecorator=>', target, key, descriptor);
}
var Person = /** @class */ (function () {
    function Person() {
        this.instanceProperty = '111';
    }
    Person.prototype.instanceMethod = function () {
    };
    ;
    Person.classMethod = function () {
    };
    __decorate([
        instancePropertyDecorator
    ], Person.prototype, "instanceProperty", void 0);
    __decorate([
        instanceMethodDecorator
    ], Person.prototype, "instanceMethod", null);
    __decorate([
        classPropertyDecorator
    ], Person, "classProperty", void 0);
    __decorate([
        classMethodDecorator
    ], Person, "classMethod", null);
    return Person;
}());
